package com.sntk.organauthomanager.infrastructure.convert;

import com.sntk.organauthomanager.domain.model.Resource;
import com.sntk.organauthomanager.domain.model.ResourceType;
import com.sntk.organauthomanager.infrastructure.db.entity.ResourceEntity;
import org.springframework.stereotype.Component;

/**
 * @ClassName: ResourceConvert
 * @author: wgchao
 * @createTime: 2020/7/21 4:32 PM
 * @Description: TODO
 */
@Component
public class ResourceConvert {
    public Resource convert(ResourceEntity resourceEntity){
        return new Resource(resourceEntity.getId(), resourceEntity.getMark(), resourceEntity.getName(), ResourceType.get(resourceEntity.getResourceType()),
                resourceEntity.getDepth(), resourceEntity.getDisabled(), resourceEntity.getParentResource(),
                resourceEntity.getVersion());
    }

    public ResourceEntity convert(Resource resource){
        ResourceEntity resourceEntity = new ResourceEntity();
        resourceEntity.setId(resource.getId());
        resourceEntity.setMark(resource.getMark());
        resourceEntity.setName(resource.getName());
        resourceEntity.setDepth(resource.getDepth());
        resourceEntity.setDisabled(resource.isDisabled());
        resourceEntity.setParentResource(resource.getParentResource());
        resourceEntity.setResourceType(resource.getResourceType().getIndex());
        resourceEntity.setVersion(resource.getVersion());
        return resourceEntity;
    }
}
